import React from 'react';
import ModalComp from './ModalComp';

import {isEmpty, isString} from 'lodash-es';

import BaseComp from "../Base/BaseComp";


// export interface ModalItemProps extends ModalCompProps{
//
// }
export default class ModalItem extends BaseComp {

    mainRender(context) {
        const { localeUtils } = this.helpers;
        const moreProps = {};
        // 如果没有保存权限，则隐藏 【确认】 按钮
// console.log(!isEmpty(localeUtils))
        moreProps.okText = !isEmpty(localeUtils)?localeUtils.formatMsgByCn('确定'):'确定';
        moreProps.cancelText = !isEmpty(localeUtils)?localeUtils.formatMsgByCn('返回'):'返回';

        // title 的国际化处理
        let { title } = this.props;
        if (isString(title)) {
            let editInd = title.indexOf('编辑');
            if (-1 !== editInd) {
                title = !isEmpty(localeUtils)?localeUtils.formatMsgByCn('crud.edit'):'编辑'+
                    (!isEmpty(localeUtils)?localeUtils.formatMsgByCn(title.substr(editInd + 2)):title.substr(editInd + 2));
            }
            // @ts-ignore
            let addInd = title.indexOf('新建');
            // @ts-ignore
            let addInd1 = title.indexOf('新增');
            addInd = -1 === addInd ? addInd1 : addInd;

            if (-1 !== addInd) {
                // @ts-ignore
                title = !isEmpty(localeUtils)?localeUtils.myFormatMessage('crud.add'):'新增' +
                    (!isEmpty(localeUtils)?localeUtils.formatMsgByCn(title.substr(addInd + 2)):title.substr(addInd + 2));
            }
        }

        return (
            <ModalComp
                {...this.props}
                {...moreProps}
                title={title}
            />
        );
    }
}
